package com.literature.search.file.task.quartz;



import com.literature.search.file.service.IFileService;
import com.literature.search.file.service.LikeAndCollectionService;
import com.literature.search.file.service.RedisService;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName SchedualedTask
 * @Description TODO
 * @Author abin
 * @Date 2023/3/24 16:27
 * @Version 1.0
 */
@Component
@EnableScheduling
public class ScheduledTask {

    @Resource
    private LikeAndCollectionService likeAndCollectionService;

    @Resource
    private IFileService fileService;

    @Resource
    private RedisService redisService;

    public void likeAndCollectionRecords2DB() throws InterruptedException{
        likeAndCollectionService.likeRecord2DB();
        likeAndCollectionService.collectRecord2DB();
    }

    /**
     * @Description 从redis更新文件的下载量,浏览量,喜欢数,点赞数;然后再从根据数据跟新ES数据
     * @param
     **/
    public void updateFile2DB2ES(){
        fileService.updateDownloadCount();
        fileService.updateViewCount();
        fileService.updateLikeCount();
        fileService.updateCollectCount();
        List<String> fileIds = redisService.getNeededUpdateFileId();
        if (fileIds.size()>0){
            fileService.updateFileToEs(fileIds);
            redisService.deleteNeededUpdateFileId(fileIds);
        }
    }

    public void SearchHotWord2DB(){
        redisService.SearchHotWord2DB();
    }
}
